<div class="hbox" style="position:relative; z-index:3;">
	<h1 class="auction_title">$auction[name]</h1>
	<div class="blank3"></div>
	<div class="auction_img">
		<a href="$auction[img]" target="_blank" class="img"><img src="$auction[img]" /></a>
		<div class="auction_user">
			<div class="user">
				<!--{if intval($_FANWE['uid']) > 0}-->
				余额:<strong id="user_money">--</strong>，此竞拍冻结:<strong id="freeze_money">0</strong>，<a href="{u site/center}" target="_blank">充值</a>
				<!--{else}-->
				请您先<a href="{u user/reg}">注册</a>或者<a href="{u user/login}">登录</a>再参与竞拍!
				<!--{/if}-->
			</div>
			<div>
				倒计时<strong>$_FANWE[setting][auction_end_time]</strong>秒内，每次出价剩余时间将增长<strong>$_FANWE[setting][auction_add_time]</strong>秒
			</div>
			<div>
				每次<img src="{TPL_PATH}images/auction/bid.gif" height="12" />出价，成交价将提高<strong>$auction[amplitude_format]</strong>
			</div>
		</div>
	</div>
	<div class="auction_info">
		<!--{if $auction['auction_status'] == 1}-->
		<div class="time successtime">竞拍已结束</div>
		<!--{else}-->
		<!--{if $auction['end_time_js'] == '0'}-->
		<div class="time time_txt">长期有效</div>
		<!--{else}-->
		<div class="time endtime" endTime="$auction[end_time_js]">--:--:--</div>
		<!--{/if}-->
		<!--{/if}-->
		<div class="auction_default{if $auction['auction_status'] == 1} hidden{/if}">
			<table class="price" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td>当前价：</td>
					<td class="auction_price"><span id="auction_price" bidPrice="$auction[base_price]">$auction[base_price_format]</span></td>
					<!--{if $auction['buyout_price'] > 0}-->
					<td>&nbsp;&nbsp;&nbsp;</td>
					<td>一口价：</td>
					<td><span>$auction[buyout_price_format]</span></td>
					<!--{/if}-->
				</tr>
			</table>
			<div class="user_img">
				<p><img src="{TPL_PATH}images/auction/user.gif" /></p>
			</div>
			<div class="user_name" id="bid_user_name">
				---
			</div>
			<table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td class="auction_btn"><a {if intval($_FANWE['uid']) > 0}href="javascript:;" class="bid"{else}href="{u user/login}" class="login"{/if}></a></td>
					<!--{if $auction['buyout_price'] > 0}-->
					<td>&nbsp;&nbsp;&nbsp;</td>
					<td class="buyout_btn"><a {if intval($_FANWE['uid']) > 0}href="javascript:;" class="bid"{else}href="{u user/login}" class="login"{/if}></a></td>
					<!--{/if}-->
				</tr>
			</table>
		</div>
		<div class="auction_end{if $auction['auction_status'] == 0} hidden{/if}">
			<table border="0" cellpadding="0" cellspacing="0" align="center">
				<tr>
					<td><span>结束时间：</span></td>
					<td class="auction_end_time"><span>--:--:--</span></td>
				</tr>
				<tr>
					<td><span>成&nbsp;交&nbsp;价：</span></td>
					<td class="auction_bid_price"><span>¥0.00</span><a></a></td>
				</tr>
				<tr>
					<td><span>起&nbsp;拍&nbsp;价：</span></td>
					<td class="auction_base_price"><span>$auction[base_price_format]</span></td>
				</tr>
				<!--{if $auction['buyout_price'] > 0}-->
				<tr>
					<td><span>一&nbsp;口&nbsp;价：</span></td>
					<td class="auction_buyout_price"><span>$auction[buyout_price_format]</span></td>
				</tr>
				<!--{/if}-->
				<tr>
					<td><span>成交会员：</span></td>
					<td class="auction_bid_user"><span>---</span></td>
				</tr>
				<!--{if $auction['buyout_price'] == 0}-->
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<!--{/if}-->
			</table>
		</div>
		<div class="blank3"></div>
		<div class="auction_attr">
			<div class="t"></div>
			<div class="m{if $auction['pre_pay'] > 0} pre_pay_m{/if}">
				<div class="item"><strong>竞拍类型</strong>：$auction[auction_type_name]&nbsp;&nbsp;&nbsp;<strong>计费类型</strong>：$auction[billing_type_name]</div>
				<!--{if $auction['pre_pay'] > 0}-->
				<div class="item"><strong>预付费金额</strong>：<span class="price">$auction[pre_pay_format]</span></div>
				<!--{/if}-->
				<div class="item"><strong>推广开始时间</strong>：$auction[validity_begin_time_format]</div>
				<div class="item"><strong>推广结束时间</strong>：$auction[validity_end_time_format]</div>
				<div class="item auction_city"><strong>推广针对城市</strong>：
				<!--{eval $first = '';$index = 1;}-->
				<!--{loop $auction['citys'] $auction_city}-->
				<!--{if $index > 3}-->
				<!--{eval break;}-->
				<!--{/if}-->
				<!--{if $auction_city['city_id'] == 0}-->
				全国
				<!--{else}-->
				{$first}{$auction_city[name]}
				<!--{/if}-->
				<!--{eval $first = ',';$index++;}-->
				<!--{/loop}-->
				<!--{if count($auction['citys']) > 3}-->
				,<a href="javascript:;" class="all_city">更多>></a>
				<div class="auction_citys hidden">
					<div class="act"></div>
					<div class="acm">
						<!--{eval $first = '';}-->
						<!--{loop $auction['citys'] $auction_city}-->
						{$first}{$auction_city[name]}
						<!--{eval $first = '、';}-->
						<!--{/if}-->
					</div>
					<div class="acb"></div>
					<div class="aci"></div>
				</div>
				<!--{/if}-->
				</div>
			</div>
			<div class="b"></div>
		</div>
	</div>
	<div class="record_rank">
		<div class="t">
			<a href="javascript:;" class="fl active" rel="record">出价记录</a>
			<a href="javascript:;" class="fr" rel="rank">出价排行</a>
		</div>
		<div class="m">
			<div class="rr_item record_list" rel="record">
				<ul>
					
				</ul>
			</div>
			<div class="rr_item rank_list hidden" rel="rank">
				<ul>
					
				</ul>
			</div>
		</div>
		<div class="b"></div>
	</div>
</div>
<div class="blank9"></div>
<div class="hbox auction_desc">
	<div class="t">
		<strong>竞拍详细介绍</strong>
	</div>
	<div class="m">
		$auction[desc]
	</div>
</div>
<script type="text/javascript">
var auction_id = {$auction[id]};
var auctionTimeOut;
var activeTime;
var isActive = true;

jQuery(function($){
	var imgWidth = $(".auction_img .img img").width();
	var imgHeight = $(".auction_img .img img").height();
	var imgX,imgY;
	if(imgWidth > 310 || imgHeight > 249)
	{
		if(imgWidth / 310 >= imgHeight / 249)
			$(".auction_img .img img").width(310);
		else
			$(".auction_img .img img").height(249);
	}
	
	imgWidth = $(".auction_img .img img").width();
	imgHeight = $(".auction_img .img img").height();
	imgX = (310 - imgWidth) / 2;
	imgY = (249 - imgHeight) / 2;
	$(".auction_img .img img").css({"top":imgY,"left":imgX});
	
	$(".record_rank .t a").click(function(){
		$(".record_rank .t a").removeClass("active");
		var rel = this.getAttribute("rel");
		$(".record_rank .t").removeClass("t_rank");
		if(rel == "rank")
			$(".record_rank .t").addClass("t_rank");
		$(this).addClass("active");
		this.blur();
		
		$(".record_rank .rr_item").hide();
		$(".record_rank .rr_item[rel='"+rel+"']").show();
	});
	
	$(".all_city").hover(function(){
		var left = $(this).position().left + $(this).width() + 3;
		var top = $(this).position().top - $(this).height() / 2;
		$(".auction_citys").css({"left":left,"top":top}).removeClass("hidden");
		$("body").one("click", function(){
			$(".auction_citys").addClass("hidden");
		});
		return false;
	},function(){});
	
	$(".auction_btn a.bid").click(function(){
		auctionBid(0);
	});
	
	$(".buyout_btn a.bid").click(function(){
		auctionBid(1);
	});
	
	var date = new Date();
	activeTime = date.getTime();
	getAuction();
	updateAuctionTime();
});

function getAuction()
{
	if(!isActive)
		return;
	
	$.ajax({
		type: "GET",
		cache:false,
		url: SITE_PATH + "/services/auction.php",
		data: {"action":"get_auction","id":auction_id},
		dataType:'json',
		success: function(data){
			if(data.uid > 0)
			{
				$("#user_money").html('¥'+data.money);
				$("#freeze_money").html('¥'+data.freeze_money);
			}
			
			if(data.bid)
			{
				var price = parseFloat($("#auction_price").get(0).getAttribute("bidPrice"))
				bidPrice = parseFloat(data.bid.price);
				if(bidPrice != price)
				{
					$("#auction_price").css({"backgroundColor":"#ff5151"}).html('¥'+bidPrice);
					$("#auction_price").stop(true,true).animate({
						backgroundColor:'#fff'
					}, 500);
					$("#auction_price").get(0).setAttribute("bidPrice",bidPrice);
				}
				
				$("#bid_user_name").html(data.bid.username);
			}
			
			if($(".endtime").length > 0)
				$(".endtime").get(0).setAttribute("endTime",data.end_time_js);
				
			var i,count,html;
			
			if(data.records)
			{
				i = 0;
				count = data.records.length;
				html = '';
				var record;
				
				for(i; i<count;i++)
				{
					record = data.records[i];
					html += '<li><span class="index_'+ (i + 1) +' index" title="' + record.username + '">' + record.username + '</span><span class="ip">' + record.auction_ip + '</span><span class="addr" title="' + record.auction_addr + '">' + record.auction_addr + '</span><span class="price">¥' + record.price + '</span></li>';
				}
				
				$(".record_list ul").html(html);
			}
			else
				$(".record_list ul").html('<li class="empty">暂无出价记录</li>');
				
			if(data.ranks)
			{
				i = 0;
				count = data.ranks.length;
				html = '';
				var rank,item;
				
				for(item in data.ranks)
				{
					rank = data.ranks[item];
					html += '<li><span class="index_'+ (i + 1) +' index">'+ (i + 1) +'</span><span class="user" title="' + rank.username + '">' + rank.username + '</span><span class="ip">' + rank.auction_ip + '</span><span class="addr" title="' + rank.auction_addr + '">' + rank.auction_addr + '</span></li>';
					i++;
				}
				
				$(".rank_list ul").html(html);
			}
			else
				$(".rank_list ul").html('<li class="empty">暂无排行记录</li>');
			
			if(data.auction_status == 0)
				auctionTimeOut = setTimeout("getAuction()",1000);
			else
			{
				$(".auction_default").hide();
				$(".auction_end").show();
				$(".time").removeClass('endtime').addClass('successtime').html("竞拍已结束");
				
				if(data.bid)
				{
					$(".auction_end_time span").html(data.bid.time_format);
					$(".auction_bid_price span").html('¥'+bidPrice);
					$(".auction_bid_price a").html("（"+data.bid.bbs_price+" 积分）");
					$(".auction_bid_user span").html(data.bid.username);
				}
				else
				{
					$(".auction_end_time span").html(data.end_time_format);
					$(".auction_bid_price span").addClass('no').html("未成交");
				}
			}
		},
		error:function(r, t, e){
			alert('连接服务器失败，请刷新页面或联系管理员！');
		}
	});
}

function auctionBid(isBuyout)
{
	clearTimeout(auctionTimeOut);
	$.ajax({
		type: "GET",
		cache:false,
		url: SITE_PATH + "/services/auction.php",
		data: {"action":"bid","id":auction_id,"is_buyout":isBuyout},
		dataType:'json',
		success: function(data){
			if(data.is_error && data.message != '')
			{
				$.showWindow({"title":"竞拍提示","html":'<div class="auction_error"><p>'+ data.message +'</p><a href="javascript:;" class="auction_close">关 闭</a></div>'});
				$(".auction_error a").click(function(){
					$("#fwindow .fwindow_close").click();
				});
			}
			
			getAuction();
		},
		error:function(r, t, e){
			alert('连接服务器失败，请刷新页面或联系管理员！');
		}
	});
}

function auctionActive()
{
	var date = new Date();
	activeTime = date.getTime();
	isActive = true;
	updateAuctionTime();
	getAuction();
}

function updateAuctionTime()
{
	var date = new Date();
	var time = date.getTime();
	
	if(time - activeTime > 600000)
		isActive = false;
	
	if(!isActive)
	{
		$.showWindow({"title":"竞拍提示","html":'<div class="auction_active"><p>您超过10分钟未进行任何操作。<br/>"继续"或关闭窗口则会激活。</p><a href="javascript:;">继 续</a></div>',closeFun:auctionActive});
		
		$(".auction_active a").click(function(){
			$("#fwindow .fwindow_close").click();
		});
		
		return false;
	}
	
	$(".endtime").each(function(i){
		var endDate =new Date(this.getAttribute("endTime"));
		var endTime = endDate.getTime();
		var ms = Math.floor(Math.floor((endTime - time) % 1000) /100);
		var lag = Math.floor((endTime - time) / 1000);
		if(lag > 0)
		{
			var second = Math.floor(lag % 60);
			var minite = Math.floor((lag / 60) % 60);
			var hour = Math.floor((lag / 3600) % 24);
			var day = Math.floor((lag / 3600) / 24);
			hour += day * 24;
			if(lag <= 10)
				$(this).html((hour > 9 ? hour : '0' + hour)+":"+(minite > 9 ? minite : '0' + minite)+":"+ (second > 9 ? second : '0' + second +"."+ ms));
			else
				$(this).html((hour > 9 ? hour : '0' + hour)+":"+(minite > 9 ? minite : '0' + minite)+":"+ (second > 9 ? second : '0' + second));
		}
		else
			$(this).html("00:00:00");
	});
	
	setTimeout("updateAuctionTime()",100);
}
</script>